var t = require("../../../api.js"), e = getApp();

Page({
    data: {
        money: 0,
        balance: 0,
        webRoot: e.webRoot,
        yue: 0,
        distribution: ""
    },
    onShow: function() {
        var o = this;
        e.request({
            url: t.bank.get_maxmoney,
            method: "post",
            data: {
                type: 1,
                default: 1
            },
            state: 1,
            success: function(t) {
                console.log(t), 1 == t.code && o.setData({
                    data: t.data,
                    balance: t.data.price
                });
            }
        });
    },
    changeInputData: function(t) {
        var e = this, o = t.currentTarget.dataset.name, a = t.detail.value;
        "money" == o && e.setData({
            money: a
        });
    },
    sendRequest: function() {
        var o = this, a = o.data.money, n = o.data.balance;
        return "" == a ? (wx.showToast({
            title: "请正确填写金额",
            icon: "none",
            mask: !0
        }), !1) : Number(a) > Number(n) ? (wx.showToast({
            title: "金额大于可提现金额",
            icon: "none",
            mask: !0
        }), !1) : a < 1 ? (wx.showToast({
            title: "提现金额至少1元",
            icon: "none",
            mask: !0
        }), !1) : (wx.showLoading({
            mask: !0
        }), void (1 == this.data.distribution ? e.request({
            url: t.user.apply,
            method: "post",
            data: {
                price: a,
                type: 0
            },
            success: function(t) {
                wx.hideLoading(), console.log("提现申请结果", t), 1 == t.code ? (wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0,
                    duration: 2e3
                }), setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 2e3)) : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0
                });
            }
        }) : 2 == this.data.distribution && e.request({
            url: t.distribution.apply,
            method: "post",
            data: {
                price: a,
                type: 0
            },
            success: function(t) {
                wx.hideLoading(), console.log("提现申请结果", t), 1 == t.code ? (wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0,
                    duration: 2e3
                }), setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 2e3)) : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    mask: !0
                });
            }
        })));
    },
    onLoad: function(t) {
        console.log(t), this.setData({
            yue: t.yue,
            distribution: t.distribution
        });
    }
});